$(function() {
	var p = {
		t : new Date(),
		listId : "SLAVE_BID_ANALYSIS.findCpbDailyCashData",
		rows : 3000,
		noCount : "true"
	};
	$.post("query.htm", p, function(data) {
		var seriesMap = [];
		for ( var i in data.rows) {
			var row = data.rows[i];
			if (!seriesMap["amount"]) {
				seriesMap["amount"] = [];
			}
			var dateTmp = row.cash_date.split("-");
			seriesMap["amount"].push([ Date.UTC(parseInt(dateTmp[0]), parseInt(dateTmp[1]) - 1, parseInt(dateTmp[2])), row.cash_amount ]);
			
			if (!seriesMap["count"]) {
				seriesMap["count"] = [];
			}
			seriesMap["count"].push([ Date.UTC(parseInt(dateTmp[0]), parseInt(dateTmp[1]) - 1, parseInt(dateTmp[2])), row.cash_count ]);
			
			if (!seriesMap["profit"]) {
				seriesMap["profit"] = [];
			}
			seriesMap["profit"].push([ Date.UTC(parseInt(dateTmp[0]), parseInt(dateTmp[1]) - 1, parseInt(dateTmp[2])), row.cash_profit ]);
		}
		
		Highcharts.setOptions({
			colors: ['#50B432','#7cb5ec','#f7a35c']
		});
		
		$('#incret_day_income').highcharts({
			chart : {
				zoomType : 'x',
				panning: true,
				panKey: 'shift'
			},
			title : {
				text : '定期每日兑付数据'
			},
			subtitle: {
				text: document.ontouchstart === undefined ? '(鼠标拖动可以进行缩放)' : '(手势操作进行缩放)'
			},
			xAxis : {
				type : 'datetime',
				dateTimeLabelFormats : {
					month : '%m',
					year : '%Y'
				},
				title : {
					text : '时间'
				}
			},
			yAxis : {
				title : {
					text : '金额(元)/笔数(笔)'
				},
				min : 0
			},
			tooltip : {
				xDateFormat: '%Y-%m-%d',
				pointFormat : '{series.name}：{point.y:.lf}<br/>',
				shared: true
			},

			plotOptions : {
				spline : {
					marker : {
						enabled : true
					}
				}
			},
			
			series : [ {
				name : '兑付笔数(笔)',
				data : seriesMap["count"]
			},{
				name : '兑付本金(元)',
				data : seriesMap["amount"]
			},{
				name : '兑付利息(元)',
				data : seriesMap["profit"]
			}]
		});
	}, "json");
	
	
		
	$("#exportExcel").click(function(){
		if(confirm("确定要导出excel吗?")) {
			window.open("exportexcel.htm?listId=SLAVE_BID_ANALYSIS.findCpbDailyCashData&rows=10000&excelname=cpb_daily_cash&");
		}
	});
});

Date.prototype.toCNString = function() {
	return this.getFullYear() + (this.getMonth()>=9 ? this.getMonth() + 1 : "0" + (this.getMonth() + 1)) + (this.getDate()>9 ? this.getDate() : "0" + this.getDate())
	 + (this.getHours()>9 ? this.getHours() : "0" + this.getHours()) + (this.getMinutes()>9 ? this.getMinutes() : "0" + this.getMinutes()) + (this.getSeconds()>9 ? this.getSeconds() : "0" + this.getSeconds());
};